package com.example.samui.case03_16110100414;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.V;

public class WelcomeActivity extends AppCompatActivity {

    private TextView tv_uname, tv_password;
    private Button button;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        tv_uname = findViewById(R.id.tv_username);
        tv_password = findViewById(R.id.tv_password);

        button = findViewById(R.id.button);

        tv_uname.setText(getIntent().getStringExtra("username"));
        tv_password.setText(getIntent().getStringExtra("password"));

        final Intent intent = new Intent(
                WelcomeActivity.this,
                                settingActivity.class);

        sp = getSharedPreferences("case03_sp", MODE_PRIVATE);

        editor = sp.edit();
        editor.putString("username",
                getIntent().getStringExtra("username"));
//        editor.putString("password",
//                getIntent().getStringExtra("password"));
        editor.commit();

        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivity(intent);
            }
        };
        button.setOnClickListener(listener);
    }
}
